package com.sise.parkinglot.controller;

import com.sise.parkinglot.bean.CodeMsg;
import com.sise.parkinglot.entity.Charger;
import com.sise.parkinglot.service.IChargerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ZJ
 */
@RestController
@RequestMapping("/parkinglot/charger")
public class ChargerController {

    @Resource
    private IChargerService chargerService;

    @PostMapping("/queryChargerList")
    public CodeMsg<List<Charger>> queryChargerList(@RequestBody Map<String, Object> map){
        return chargerService.queryChargerList(map);
    }

    @PostMapping("/addCharger")
    public CodeMsg<String> addCharger(@RequestBody Charger charger){
        return chargerService.addCharger(charger);
    }

    @PostMapping("/removeCharger")
    public CodeMsg<String> removeCharger(@RequestBody int[] ids){
        return chargerService.removeCharger(ids);
    }

    @PostMapping("/upCharger")
    public CodeMsg<String> upCharger(@RequestBody int[] ids){
        return chargerService.updateState(ids, 1);
    }

    @PostMapping("/downCharger")
    public CodeMsg<String> downCharger(@RequestBody int[] ids){
        return chargerService.updateState(ids, 2);
    }

    @PostMapping("/updateCharger")
    public CodeMsg<String> updateCharger(@RequestBody Charger charger){
        return chargerService.updateCharger(charger);
    }

}
